#coding=utf-8
# Copyright 2011-2012 Maxim Petrov <maximpetrov@yahoo.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 3 or any later version.

from revision_panel import RevisionPanel
import curses

class OutgoingPanel(RevisionPanel):
    """This class used for draw panel that show table of outgoing revisions"""

    _panel_header = _(u'Outgoing')
    conflicts_panel = None

    def __init__(self, main_window):
        """
        Constructor of outgoing panel

        Keyword arguments:
        main_window -- instance of MainWindow
        """

        RevisionPanel.__init__(self, main_window)
        self.hotkeys.update({5: _(u'Check')})

    def _get_table_content(self):
        """
        Function to get content to show in table
        """

        return self._main_window.repo_util.get_outgoing()

    def _no_revisions_string(self):
        """
        Function for get string reports that there are no revisions to show
        """

        return _(u"No outgoing revisions")

    def handle_keypress(self, ch, uni):
        """
        Handle keypress.

        Keyword arguments:
        ch -- pressed key
        uni -- True if ch is Unicode symbol, False otherwise
        """

        if ch == curses.KEY_F5:
            self._main_window._update_inout_panels()
        elif ch == ord('\n'):
            rev = self.get_selected_revision_number()
            if rev is not None:
                self.conflicts_panel.set_revision_view(rev, u'out')
        else:
            RevisionPanel.handle_keypress(self, ch, uni)
